#pragma once

class TransportManage
{
public:
	enum class State
	{
		Idle = 0,
		Send = 1,
		Receive = 2
	};
	typedef void (__cdecl* CallbackFunc)();

public:
	static void threadfunc_Send(TransportManage* tpmanage);
	static void threadfunc_Receive(TransportManage* tpmanage);

public:
	TransportManage(size_t buffsize, CallbackFunc callbackfunc);
	~TransportManage();

public:
	void GetProgressText(TCHAR text[256]);
	int Start(const State state, const TCHAR targetip[16], const TCHAR targetport[6]);
	void Reset();

public:
	State getState() const;
	void addFile(FileInfo* pfi);

private:
	CallbackFunc _callbackfunc;

	State _state;

	uint64_t _startTime;
	uint64_t _lastTime;
	filesize_t _lastFileSize;
	filesize_t _nowFileSize;
	filesize_t _sumFileSize;

	size_t _buffsize;
	BYTE* _buff;

	std::vector<FileInfo> _filelist;

	SOCKET _sock_receiver;
	SOCKADDR_IN _sockaddr_receiver;
};